const { sequelize } = require('../config/database');
const User = require('./User');
const StudyProgress = require('./StudyProgress');
const CheckIn = require('./CheckIn');
const Resource = require('./Resource');

// 定义模型关联关系
User.hasMany(StudyProgress, { foreignKey: 'user_id', as: 'studyProgress' });
StudyProgress.belongsTo(User, { foreignKey: 'user_id', as: 'user' });

User.hasMany(CheckIn, { foreignKey: 'user_id', as: 'checkins' });
CheckIn.belongsTo(User, { foreignKey: 'user_id', as: 'user' });

User.hasMany(Resource, { foreignKey: 'created_by', as: 'createdResources' });
Resource.belongsTo(User, { foreignKey: 'created_by', as: 'creator' });

module.exports = {
  sequelize,
  User,
  StudyProgress,
  CheckIn,
  Resource
}; 